setwd("/home/jar/zxjar/paper_helper/attachment/0/63")
library(readr)
library(compareGroups)
library(dplyr)

mydata <- read_csv("data.csv")
mydata<-na.omit(mydata)

mydata = mydata %>% dplyr::mutate(across(f_education, as.factor))

library(caret)
dev = mydata[mydata$s_group==1,]
vad = mydata[mydata$s_group==0,]

table1<-descrTable(~ uid+type+x_age+f_education+x_sex+x_bmi+x_smoking+x_side_of_dvt_left+x_side_of_dvt_bilateral+x_symptom_pain+x_symptom_edema+x_symptom_pain_on_calf_compression+x_ilio_femoral_dvt+x_risk_factors_of_dvt_surgery_and_immobilization+x_risk_factors_of_dvt_fracture+x_risk_factors_of_dvt_active_cancer+x_risk_factors_of_dvt_hyperhomocysteinemia+x_risk_factors_of_dvt_cvi+x_risk_factors_of_dvt_history_of_vte+x_risk_factors_of_dvt_pregnancy+x_risk_factors_of_dvt_thrombophilia+x_risk_factors_of_dvt_chronic_kidney_disease+x_risk_factors_of_dvt_oral_contraceptive+x_risk_factors_of_dvt_family_history_of_dvt+x_risk_factors_of_dvt_unprovoked+x_comorbidity_hypertension+x_comorbidity_pe+x_comorbidity_stroke+x_comorbidity_diabetes+x_comorbidity_coronary_heart_disease+x_comorbidity_immune_rheumatism+x_types_of_anticoagulants_lmwh+x_types_of_anticoagulants_doacs+x_types_of_anticoagulants_vka+x_types_of_anticoagulants_other+x_duration_of_compression_therapy_xiaoyu_6_mon+x_d_dimmer+y_post_thrombotic_syndrome+s_group,data = mydata,method = c(uid=NA,type=NA,x_age=NA,f_education=NA,x_sex=NA,x_bmi=NA,x_smoking=NA,x_side_of_dvt_left=NA,x_side_of_dvt_bilateral=NA,x_symptom_pain=NA,x_symptom_edema=NA,x_symptom_pain_on_calf_compression=NA,x_ilio_femoral_dvt=NA,x_risk_factors_of_dvt_surgery_and_immobilization=NA,x_risk_factors_of_dvt_fracture=NA,x_risk_factors_of_dvt_active_cancer=NA,x_risk_factors_of_dvt_hyperhomocysteinemia=NA,x_risk_factors_of_dvt_cvi=NA,x_risk_factors_of_dvt_history_of_vte=NA,x_risk_factors_of_dvt_pregnancy=NA,x_risk_factors_of_dvt_thrombophilia=NA,x_risk_factors_of_dvt_chronic_kidney_disease=NA,x_risk_factors_of_dvt_oral_contraceptive=NA,x_risk_factors_of_dvt_family_history_of_dvt=NA,x_risk_factors_of_dvt_unprovoked=NA,x_comorbidity_hypertension=NA,x_comorbidity_pe=NA,x_comorbidity_stroke=NA,x_comorbidity_diabetes=NA,x_comorbidity_coronary_heart_disease=NA,x_comorbidity_immune_rheumatism=NA,x_types_of_anticoagulants_lmwh=NA,x_types_of_anticoagulants_doacs=NA,x_types_of_anticoagulants_vka=NA,x_types_of_anticoagulants_other=NA,x_duration_of_compression_therapy_xiaoyu_6_mon=NA,x_d_dimmer=NA,y_post_thrombotic_syndrome=NA,s_group=NA))
sink("logit_baseline1.txt")
table1
sink()
export2xls(table1,file = "logit_baseline1.xls")

dfx = mydata %>% select(y_post_thrombotic_syndrome,x_age,f_education,x_sex,x_bmi,x_smoking,x_side_of_dvt_left,x_side_of_dvt_bilateral,x_symptom_pain,x_symptom_edema,x_symptom_pain_on_calf_compression,x_ilio_femoral_dvt,x_risk_factors_of_dvt_surgery_and_immobilization,x_risk_factors_of_dvt_fracture,x_risk_factors_of_dvt_active_cancer,x_risk_factors_of_dvt_hyperhomocysteinemia,x_risk_factors_of_dvt_cvi,x_risk_factors_of_dvt_history_of_vte,x_risk_factors_of_dvt_pregnancy,x_risk_factors_of_dvt_thrombophilia,x_risk_factors_of_dvt_chronic_kidney_disease,x_risk_factors_of_dvt_oral_contraceptive,x_risk_factors_of_dvt_family_history_of_dvt,x_risk_factors_of_dvt_unprovoked,x_comorbidity_hypertension,x_comorbidity_pe,x_comorbidity_stroke,x_comorbidity_diabetes,x_comorbidity_coronary_heart_disease,x_comorbidity_immune_rheumatism,x_types_of_anticoagulants_lmwh,x_types_of_anticoagulants_doacs,x_types_of_anticoagulants_vka,x_types_of_anticoagulants_other,x_duration_of_compression_therapy_xiaoyu_6_mon,x_d_dimmer) %>% dplyr::rename("group"=1)
table2<-descrTable(group~.,data = dfx,method = c(x_age=NA,f_education=NA,x_sex=NA,x_bmi=NA,x_smoking=NA,x_side_of_dvt_left=NA,x_side_of_dvt_bilateral=NA,x_symptom_pain=NA,x_symptom_edema=NA,x_symptom_pain_on_calf_compression=NA,x_ilio_femoral_dvt=NA,x_risk_factors_of_dvt_surgery_and_immobilization=NA,x_risk_factors_of_dvt_fracture=NA,x_risk_factors_of_dvt_active_cancer=NA,x_risk_factors_of_dvt_hyperhomocysteinemia=NA,x_risk_factors_of_dvt_cvi=NA,x_risk_factors_of_dvt_history_of_vte=NA,x_risk_factors_of_dvt_pregnancy=NA,x_risk_factors_of_dvt_thrombophilia=NA,x_risk_factors_of_dvt_chronic_kidney_disease=NA,x_risk_factors_of_dvt_oral_contraceptive=NA,x_risk_factors_of_dvt_family_history_of_dvt=NA,x_risk_factors_of_dvt_unprovoked=NA,x_comorbidity_hypertension=NA,x_comorbidity_pe=NA,x_comorbidity_stroke=NA,x_comorbidity_diabetes=NA,x_comorbidity_coronary_heart_disease=NA,x_comorbidity_immune_rheumatism=NA,x_types_of_anticoagulants_lmwh=NA,x_types_of_anticoagulants_doacs=NA,x_types_of_anticoagulants_vka=NA,x_types_of_anticoagulants_other=NA,x_duration_of_compression_therapy_xiaoyu_6_mon=NA,x_d_dimmer=NA),show.all=TRUE)
sink("logit_baseline2.txt")
table2
sink()
export2xls(table2,file = "logit_baseline2.xls")

train=dev %>% dplyr::mutate(Groupsp="Train")
test=vad %>% dplyr::mutate(Groupsp="Test")
dfx = rbind(train,test) %>% select(y_post_thrombotic_syndrome,x_age,f_education,x_sex,x_bmi,x_smoking,x_side_of_dvt_left,x_side_of_dvt_bilateral,x_symptom_pain,x_symptom_edema,x_symptom_pain_on_calf_compression,x_ilio_femoral_dvt,x_risk_factors_of_dvt_surgery_and_immobilization,x_risk_factors_of_dvt_fracture,x_risk_factors_of_dvt_active_cancer,x_risk_factors_of_dvt_hyperhomocysteinemia,x_risk_factors_of_dvt_cvi,x_risk_factors_of_dvt_history_of_vte,x_risk_factors_of_dvt_pregnancy,x_risk_factors_of_dvt_thrombophilia,x_risk_factors_of_dvt_chronic_kidney_disease,x_risk_factors_of_dvt_oral_contraceptive,x_risk_factors_of_dvt_family_history_of_dvt,x_risk_factors_of_dvt_unprovoked,x_comorbidity_hypertension,x_comorbidity_pe,x_comorbidity_stroke,x_comorbidity_diabetes,x_comorbidity_coronary_heart_disease,x_comorbidity_immune_rheumatism,x_types_of_anticoagulants_lmwh,x_types_of_anticoagulants_doacs,x_types_of_anticoagulants_vka,x_types_of_anticoagulants_other,x_duration_of_compression_therapy_xiaoyu_6_mon,x_d_dimmer,Groupsp) %>% dplyr::rename("group"=1) %>% mutate(Groupsp=factor(Groupsp))
table3<-descrTable(Groupsp~.,data = dfx,method = c(x_age=NA,f_education=NA,x_sex=NA,x_bmi=NA,x_smoking=NA,x_side_of_dvt_left=NA,x_side_of_dvt_bilateral=NA,x_symptom_pain=NA,x_symptom_edema=NA,x_symptom_pain_on_calf_compression=NA,x_ilio_femoral_dvt=NA,x_risk_factors_of_dvt_surgery_and_immobilization=NA,x_risk_factors_of_dvt_fracture=NA,x_risk_factors_of_dvt_active_cancer=NA,x_risk_factors_of_dvt_hyperhomocysteinemia=NA,x_risk_factors_of_dvt_cvi=NA,x_risk_factors_of_dvt_history_of_vte=NA,x_risk_factors_of_dvt_pregnancy=NA,x_risk_factors_of_dvt_thrombophilia=NA,x_risk_factors_of_dvt_chronic_kidney_disease=NA,x_risk_factors_of_dvt_oral_contraceptive=NA,x_risk_factors_of_dvt_family_history_of_dvt=NA,x_risk_factors_of_dvt_unprovoked=NA,x_comorbidity_hypertension=NA,x_comorbidity_pe=NA,x_comorbidity_stroke=NA,x_comorbidity_diabetes=NA,x_comorbidity_coronary_heart_disease=NA,x_comorbidity_immune_rheumatism=NA,x_types_of_anticoagulants_lmwh=NA,x_types_of_anticoagulants_doacs=NA,x_types_of_anticoagulants_vka=NA,x_types_of_anticoagulants_other=NA,x_duration_of_compression_therapy_xiaoyu_6_mon=NA,x_d_dimmer=NA),show.all=TRUE)
sink("logit_baseline3.txt")
table3
sink()
export2xls(table3,file = "logit_baseline3.xls")


dfx = dev %>% select(y_post_thrombotic_syndrome,x_age,f_education,x_sex,x_bmi,x_smoking,x_side_of_dvt_left,x_side_of_dvt_bilateral,x_symptom_pain,x_symptom_edema,x_symptom_pain_on_calf_compression,x_ilio_femoral_dvt,x_risk_factors_of_dvt_surgery_and_immobilization,x_risk_factors_of_dvt_fracture,x_risk_factors_of_dvt_active_cancer,x_risk_factors_of_dvt_hyperhomocysteinemia,x_risk_factors_of_dvt_cvi,x_risk_factors_of_dvt_history_of_vte,x_risk_factors_of_dvt_pregnancy,x_risk_factors_of_dvt_thrombophilia,x_risk_factors_of_dvt_chronic_kidney_disease,x_risk_factors_of_dvt_oral_contraceptive,x_risk_factors_of_dvt_family_history_of_dvt,x_risk_factors_of_dvt_unprovoked,x_comorbidity_hypertension,x_comorbidity_pe,x_comorbidity_stroke,x_comorbidity_diabetes,x_comorbidity_coronary_heart_disease,x_comorbidity_immune_rheumatism,x_types_of_anticoagulants_lmwh,x_types_of_anticoagulants_doacs,x_types_of_anticoagulants_vka,x_types_of_anticoagulants_other,x_duration_of_compression_therapy_xiaoyu_6_mon,x_d_dimmer) %>% dplyr::rename("group"=1)
table4<-descrTable(group~.,data = dfx,method = c(x_age=NA,f_education=NA,x_sex=NA,x_bmi=NA,x_smoking=NA,x_side_of_dvt_left=NA,x_side_of_dvt_bilateral=NA,x_symptom_pain=NA,x_symptom_edema=NA,x_symptom_pain_on_calf_compression=NA,x_ilio_femoral_dvt=NA,x_risk_factors_of_dvt_surgery_and_immobilization=NA,x_risk_factors_of_dvt_fracture=NA,x_risk_factors_of_dvt_active_cancer=NA,x_risk_factors_of_dvt_hyperhomocysteinemia=NA,x_risk_factors_of_dvt_cvi=NA,x_risk_factors_of_dvt_history_of_vte=NA,x_risk_factors_of_dvt_pregnancy=NA,x_risk_factors_of_dvt_thrombophilia=NA,x_risk_factors_of_dvt_chronic_kidney_disease=NA,x_risk_factors_of_dvt_oral_contraceptive=NA,x_risk_factors_of_dvt_family_history_of_dvt=NA,x_risk_factors_of_dvt_unprovoked=NA,x_comorbidity_hypertension=NA,x_comorbidity_pe=NA,x_comorbidity_stroke=NA,x_comorbidity_diabetes=NA,x_comorbidity_coronary_heart_disease=NA,x_comorbidity_immune_rheumatism=NA,x_types_of_anticoagulants_lmwh=NA,x_types_of_anticoagulants_doacs=NA,x_types_of_anticoagulants_vka=NA,x_types_of_anticoagulants_other=NA,x_duration_of_compression_therapy_xiaoyu_6_mon=NA,x_d_dimmer=NA),show.all=TRUE)
sink("logit_baseline4.txt")
table4
sink()
export2xls(table4,file = "logit_baseline4.xls")


dfx = vad %>% select(y_post_thrombotic_syndrome,x_age,f_education,x_sex,x_bmi,x_smoking,x_side_of_dvt_left,x_side_of_dvt_bilateral,x_symptom_pain,x_symptom_edema,x_symptom_pain_on_calf_compression,x_ilio_femoral_dvt,x_risk_factors_of_dvt_surgery_and_immobilization,x_risk_factors_of_dvt_fracture,x_risk_factors_of_dvt_active_cancer,x_risk_factors_of_dvt_hyperhomocysteinemia,x_risk_factors_of_dvt_cvi,x_risk_factors_of_dvt_history_of_vte,x_risk_factors_of_dvt_pregnancy,x_risk_factors_of_dvt_thrombophilia,x_risk_factors_of_dvt_chronic_kidney_disease,x_risk_factors_of_dvt_oral_contraceptive,x_risk_factors_of_dvt_family_history_of_dvt,x_risk_factors_of_dvt_unprovoked,x_comorbidity_hypertension,x_comorbidity_pe,x_comorbidity_stroke,x_comorbidity_diabetes,x_comorbidity_coronary_heart_disease,x_comorbidity_immune_rheumatism,x_types_of_anticoagulants_lmwh,x_types_of_anticoagulants_doacs,x_types_of_anticoagulants_vka,x_types_of_anticoagulants_other,x_duration_of_compression_therapy_xiaoyu_6_mon,x_d_dimmer) %>% dplyr::rename("group"=1)
table5<-descrTable(group~.,data = dfx,method = c(x_age=NA,f_education=NA,x_sex=NA,x_bmi=NA,x_smoking=NA,x_side_of_dvt_left=NA,x_side_of_dvt_bilateral=NA,x_symptom_pain=NA,x_symptom_edema=NA,x_symptom_pain_on_calf_compression=NA,x_ilio_femoral_dvt=NA,x_risk_factors_of_dvt_surgery_and_immobilization=NA,x_risk_factors_of_dvt_fracture=NA,x_risk_factors_of_dvt_active_cancer=NA,x_risk_factors_of_dvt_hyperhomocysteinemia=NA,x_risk_factors_of_dvt_cvi=NA,x_risk_factors_of_dvt_history_of_vte=NA,x_risk_factors_of_dvt_pregnancy=NA,x_risk_factors_of_dvt_thrombophilia=NA,x_risk_factors_of_dvt_chronic_kidney_disease=NA,x_risk_factors_of_dvt_oral_contraceptive=NA,x_risk_factors_of_dvt_family_history_of_dvt=NA,x_risk_factors_of_dvt_unprovoked=NA,x_comorbidity_hypertension=NA,x_comorbidity_pe=NA,x_comorbidity_stroke=NA,x_comorbidity_diabetes=NA,x_comorbidity_coronary_heart_disease=NA,x_comorbidity_immune_rheumatism=NA,x_types_of_anticoagulants_lmwh=NA,x_types_of_anticoagulants_doacs=NA,x_types_of_anticoagulants_vka=NA,x_types_of_anticoagulants_other=NA,x_duration_of_compression_therapy_xiaoyu_6_mon=NA,x_d_dimmer=NA),show.all=TRUE)
sink("logit_baseline5.txt")
table5
sink()
export2xls(table2,file = "logit_baseline5.xls")